<?php
class ConsumeAction extends Action{
     function _initialize(){
         if(!isset($_SESSION[C('USER_AUTH_KEY')])){
             $this -> redirect('login', 'Public');
             }
         parent :: _initialize();
         }
     function index(){
         $userId = $_SESSION[C('USER_AUTH_KEY')];
         $allFakeUrls = getUserURL($userId);
         $model = D("Consume");
         import("ORG.Util.HashMap");
         $condition = new HashMap();
         $condition -> put("fid", array("IN", $allFakeUrls));
         $count = $model -> count($condition);
         $fakedata = $model -> findAll($condition);
         $condition -> put("flag", "1");
         $realcount = $model -> count($condition);
         $realdata = $model -> findAll($condition);
		 $usefulFee = 0;
		 foreach($realdata as $singledata){
				$usefulFee+=$singledata['count'];
		 }
         if($count > 0){
             import("ORG.Util.Page");
             if(!empty($_REQUEST['listRows'])){
                 $listRows = $_REQUEST['listRows'];
                 }else{
                 $listRows = '';
                 }
             $p = new Page($count, $listRows);
             $page = $p -> show();
				$pagedetail = $model->where("fid IN (".$allFakeUrls.")")->limit($p->firstRow.','.$p->listRows)->order("`consume_time` DESC")->findAll();
             }
			 $this->assign("usefulFee",$usefulFee);
			 $this->assign("yourFee",$usefulFee * 0.7);
			 $this->assign("list",$pagedetail);
			 $this->assign("page",$page);
			 $this->display();
         }
     }
?>